#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

//Label=new QLabel(ui->video_widget);
my_webcam=new video;

my_webcam->load_cam();
connect(my_webcam,SIGNAL(video_updated(QImage)),this,SLOT(set_background_video(QImage )));
connect(my_webcam,SIGNAL(match(double)),this,SLOT(match(double)));
connect(my_webcam,SIGNAL(result(int)),this,SLOT(result(int)));
}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::set_background_video(QImage im)
{
/*
QPixmap pixmap;
QPalette palette;

QImage Image;
if(ui->video_widget->height()<ui->video_widget->width())
{
Image = im.scaledToHeight(ui->video_widget->height(),Qt::FastTransformation);
}
else
{Image = im.scaledToWidth(ui->video_widget->width(),Qt::FastTransformation);}

pixmap.convertFromImage(Image,0);
Label->setPixmap(pixmap);
Label->resize(pixmap.size());
ui->video_widget->setPalette(palette);

*/}

void  MainWindow::closeEvent(QCloseEvent* event) {

    my_webcam->end();

  event->accept();

}

void MainWindow::match(double matchnb)
{
ui->MATCH->display(matchnb);
//ui->progress_MATCH->setValue(matchnb*100);
}

void MainWindow::result(int i)
{
//ui->RESULT->display(i);
}


void MainWindow::on_pushButton_clicked()
{

     //my_webcam->running=false;
my_webcam->start();
}



void MainWindow::on_descriptor_toggled(bool checked)
{
  my_webcam->see_descriptor=checked;
}

void MainWindow::on_doubleSpinBox_valueChanged(double arg1)
{
   my_webcam->ratiomin=arg1;
}
